import jqdatasdk
import pandas as pd

# ---login---
jqdatasdk.auth("18612237128", "Kirk_1984")

stocks = jqdatasdk.get_all_securities(types=['stock'])
a = 0

industries = jqdatasdk.get_industry(list(stocks.index), date="2018-06-01")

data = []
for symbol, value in industries.items():
    entry = [None, None, None, None, None, None]
    fields = ["sw_l1", "sw_l2", "sw_l3", "zjw", "jq_l1", "jq_l2"]
    for i in range(len(fields)):
        v = value.get(fields[i])
        if v != None:
            entry[i] = v["industry_name"]
    data.append([symbol] + entry)

#
df = pd.DataFrame(data, columns=["Symbol"] + fields)
df.to_csv("d:/data/industry/JQIndustry.csv")

b = 0